- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.5k
 
fix(react-query): update Incorrect Inference of GetDefinedOrUndefinedQueryResult when TData is assignable to CallableFunction #9278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…QueryResult when TData is assignable to CallableFunction * Only consider the initialData pathway in GetDefinedOrUndefinedQueryResult when the key is defined * test CallableFunction case for useQueries
| 
           I can see that my  Please let me know if I should revert the lock file change, as this should not affect this PR with or without it. Noting that running pnpm build:all also fails against vue - this change only affects react-query  | 
    
          
 you were definitely using the wrong version, I can see that  - lockfileVersion: '9.0'
+ lockfileVersion: '6.0'so yeah, definitely the wrong version of   | 
    
          
 Sorry about the time waste here. I just shouldn't have committed it in the first place. I've reverted that change now  | 
    
| 
           View your CI Pipeline Execution ↗ for commit 3250700. 
 ☁️ Nx Cloud last updated this comment at   | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressing some lint errors
| 
           we now have a bunch of type errors:  | 
    
          
 Didn't get around to this one on the weekend, I'll look into this during the week.  | 
    
5d7869e    to
    18a12ca      
    Compare
  
    
Overview
This PR resolves an issue that was brought up in discord where using
queryOptionswhere TQueryFnData was{ name: string }, would cause the type of TData onuseQueriesto be{ name: string }instead of{ name: string } | undefined.Upon further investigation into what was causing this, it looks like because
InitialDatais assignabled to{ name: string }when it is a function (since name is a key on CallableFunction in typescript), the type would assume the wrong pathway in theGetDefinedOrUndefinedQueryResulttype, resulting in the incorrect return type.Changing the initial condition from
T extends { initialData?: ... }toT extends { initialData: ... }allows us to avoid hitting that pathway altogether and gives the correct type.Tests
I have updated the tests to ensure this case is correctly tested against, and ensured that existing tests are not affected. I have also slightly restructured the tests specifically testing
queryOptionsunder a describe for better code organization.Original Issue
Discord Thread: https://discord.com/channels/719702312431386674/1382540005624512532